package org.spark.api.controller;

import org.apache.commons.codec.digest.DigestUtils;
import org.spark.api.constant.DyTable;
import org.spark.api.dao.hbase.DetailsProductDateAuthorAwemeDao;
import org.spark.api.entity.DetailsProductDateAuthorAweme;
import org.spark.api.util.MsgPackWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @author chenwy
 */
@RestController
@RequestMapping("details-product-date-author-aweme")
public class DetailsProductDateAuthorAwemeController {

    private DetailsProductDateAuthorAwemeDao dao;

    @Autowired
    public void setDao(DetailsProductDateAuthorAwemeDao dao) {
        this.dao = dao;
    }

    @GetMapping(value = "list")
    public List<DetailsProductDateAuthorAweme> list(@RequestParam String productId) throws IOException {
        MsgPackWriter writer = MsgPackWriter.create();
        byte [] rowPrefix = writer.pack(DigestUtils.sha1Hex(productId)).toByteArray();
        writer.close();
        return dao.scan(DyTable.DETAILS_PRODUCT_DATE_AUTHOR_AWEME.getTableName(), rowPrefix);
    }
}
